var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    examSetting:{

    },
    isExamFinished: false,
    totalScore:0,//考试得分
   
    btnTitle:'下一题',
    isStarted: false,
    current: 0,
    total: 160,
    remainTime: 0,
    minutes: 90,
    subjectList: [
     
    ]

  },

  startexam: function () {
    this.setData({ 'isStarted': true });
    var me=this;
    app.util.request({
      url:"entry/wxapp/getExamSubjects",
      data:{
        m:"rs_anwser",
        subjectType:'single'
      },
      success:function(data){
        
           me.setData({
             subjectList:data.data.data,
             total: data.data.data.length
           })
      }
    })
  },

  updateSubjectList: function (data) {
   
    this.setData({ subjectList: data });
  },

 
  /**
   * 选择题目选项
   */
  selectOption: function (e) {


    var subject = getApp().subjectPage.getCurrentSubject(this);
    var index = e.currentTarget.dataset.index;
  
    var options = subject.options;
    for(var i=0;i<options.length;i++){
      options[i].resultClass = '';
    }
    options[index]['resultClass'] = 'option-select';

    subject.options = options;
    subject.selectOption = options[index].label;
    getApp().subjectPage.updateCurrentSubject(this, subject);

  },

  updateCurrent: function (data) {
    this.setData({ current: data.detail });
  },
 
  updateRemainTime: function (e) {
    this.setData({ remainTime: e.detail.remainTime });

  },

  updateTotalScore:function(e){
    console.log(e);
    this.setData({ totalScore: e.detail,isExamFinished:true});
  },
  changeSubject: function (e) {
    if (e.detail.current == this.data.subjectList.length-1){
      this.setData({btnTitle:'交卷'});
    } else if(e.detail.current == this.data.subjectList.length-2){
      this.setData({ btnTitle: '下一题' });
    }
    this.setData({ current: e.detail.current });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var me = this;
    app.util.request({
      url:'entry/wxapp/getExamSetting',
      data:{
         m:'rs_anwser',
         subjectType:'single'
      },
      success:function(data){
      
         var temp = data.data.data;
         var examSetting = {duration:temp.duration,title:temp.title,totalScore:temp.setting.single.total_score,perScore:temp.setting.single.per_score};
          me.setData({examSetting:examSetting});

          me.setData({ 'minites': temp.duration, 'remainTime': getApp().subjectPage.getRemainTime(temp.duration * 60) });

        
      }
    })

   

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})